package com.aaa.a1107.demo03;

/**
 * @author 荆豪峰
 * @version 1.0
 */
public class Singleton {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            public void run() {
                System.out.println(Singleton.getInstance());
            }
        }).start();
        new Thread(new Runnable() {
            public void run() {
                System.out.println(Singleton.getInstance());
            }
        }).start();
    }
    //懒汉式
     private Singleton() {

     }
    private volatile static Singleton singleton;
     public static Singleton getInstance() {
         if (singleton == null) {
             synchronized (Singleton.class) {
                 if (singleton == null) {
                     singleton = new Singleton();
                 }
             }
         }
         return singleton;
     }
     public void show(){
         System.out.println("===========");
     }
}
